package com.example.mobile2021606159yhf0407;

import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;

public class MainActivity extends AppCompatActivity {
    private TextView tvMainTitle;
    private Button btnMainRec;
    private ConstraintLayout constraintLayout2;
    private TextView tvMainTopic1;
    private TextView tvMainTopic2;
    private TextView tvMainTopic3;
    private TextView tvMainTopic4;
    private RadioGroup radGupMainTopic1;
    private RadioButton radBtnMainTopic1A;
    private RadioButton radBtnMainTopic1B;
    private RadioButton radBtnMainTopic1C;
    private RadioButton radBtnMainTopic1D;
    private RadioGroup radGupMainTopic2;
    private RadioButton radBtnMainTopic2A;
    private RadioButton radBtnMainTopic2B;
    private RadioButton radBtnMainTopic2C;
    private RadioButton radBtnMainTopic2D;
    private RadioGroup radGupMainTopic3;
    private RadioButton radBtnMainTopic3A;
    private RadioButton radBtnMainTopic3B;
    private RadioButton radBtnMainTopic3C;
    private RadioButton radBtnMainTopic3D;
    private RadioGroup radGupMainTopic4;
    private RadioButton radBtnMainTopic4A;
    private RadioButton radBtnMainTopic4B;
    private RadioButton radBtnMainTopic4C;
    private RadioButton radBtnMainTopic4D;
    private Button btnMainSubmit;
    private TextView tvMainResult;
    RadioGroup[] rad = new RadioGroup[]{radGupMainTopic1};
    RadioButton[] radioButtons = new RadioButton[]{};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        btnMainSubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (radGupMainTopic1.getCheckedRadioButtonId() != -1 && radGupMainTopic2.getCheckedRadioButtonId() != -1){
                    if (radGupMainTopic3.getCheckedRadioButtonId() != -1 && radGupMainTopic4.getCheckedRadioButtonId() != -1){
                        int grader = 0;
                        if(radBtnMainTopic1A.isChecked()){
                            grader += 25;
                        }
                        if(radBtnMainTopic2C.isChecked()){
                            grader += 25;
                        }
                        if(radBtnMainTopic3B.isChecked()){
                            grader += 25;
                        }
                        if(radBtnMainTopic4A.isChecked()){
                            grader += 25;
                        }
                        tvMainResult.setText("分数："+grader);
                        grader = 0;
                    }else {
                        tvMainResult.setText("未完成");
                    }
                }else {
                    tvMainResult.setText("未完成");
                }
            }
        });
        btnMainRec.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                radGupMainTopic1.clearCheck();
                radGupMainTopic2.clearCheck();
                radGupMainTopic3.clearCheck();
                radGupMainTopic4.clearCheck();
                tvMainResult.setText("分数：");
            }
        });

    }
    private void initView() {
        tvMainTitle = (TextView) findViewById(R.id.tv_main_title);
        btnMainRec = (Button) findViewById(R.id.btn_main_rec);
        constraintLayout2 = (ConstraintLayout) findViewById(R.id.constraintLayout2);
        tvMainTopic1 = (TextView) findViewById(R.id.tv_main_topic1);
        tvMainTopic2 = (TextView) findViewById(R.id.tv_main_topic2);
        tvMainTopic3 = (TextView) findViewById(R.id.tv_main_topic3);
        tvMainTopic4 = (TextView) findViewById(R.id.tv_main_topic4);
        radGupMainTopic1 = (RadioGroup) findViewById(R.id.radGup_main_topic1);
        radBtnMainTopic1A = (RadioButton) findViewById(R.id.radBtn_main_topic1_A);
        radBtnMainTopic1B = (RadioButton) findViewById(R.id.radBtn_main_topic1_B);
        radBtnMainTopic1C = (RadioButton) findViewById(R.id.radBtn_main_topic1_C);
        radBtnMainTopic1D = (RadioButton) findViewById(R.id.radBtn_main_topic1_D);
        radGupMainTopic2 = (RadioGroup) findViewById(R.id.radGup_main_topic2);
        radBtnMainTopic2A = (RadioButton) findViewById(R.id.radBtn_main_topic2_A);
        radBtnMainTopic2B = (RadioButton) findViewById(R.id.radBtn_main_topic2_B);
        radBtnMainTopic2C = (RadioButton) findViewById(R.id.radBtn_main_topic2_C);
        radBtnMainTopic2D = (RadioButton) findViewById(R.id.radBtn_main_topic2_D);
        radGupMainTopic3 = (RadioGroup) findViewById(R.id.radGup_main_topic3);
        radBtnMainTopic3A = (RadioButton) findViewById(R.id.radBtn_main_topic3_A);
        radBtnMainTopic3B = (RadioButton) findViewById(R.id.radBtn_main_topic3_B);
        radBtnMainTopic3C = (RadioButton) findViewById(R.id.radBtn_main_topic3_C);
        radBtnMainTopic3D = (RadioButton) findViewById(R.id.radBtn_main_topic3_D);
        radGupMainTopic4 = (RadioGroup) findViewById(R.id.radGup_main_topic4);
        radBtnMainTopic4A = (RadioButton) findViewById(R.id.radBtn_main_topic4_A);
        radBtnMainTopic4B = (RadioButton) findViewById(R.id.radBtn_main_topic4_B);
        radBtnMainTopic4C = (RadioButton) findViewById(R.id.radBtn_main_topic4_C);
        radBtnMainTopic4D = (RadioButton) findViewById(R.id.radBtn_main_topic4_D);
        btnMainSubmit = (Button) findViewById(R.id.btn_main_submit);
        tvMainResult = (TextView) findViewById(R.id.tv_main_result);
    }
}